package com.bridge.applets.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

import java.sql.SQLException;
@Slf4j
public class CusPagInterceptor extends PaginationInnerInterceptor {
    public CusPagInterceptor(DbType dbType) {
        super(dbType);
    }

    @Override
    public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        log.info("CusPagInterceptor---->willDoQuery");
        return super.willDoQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
    }

    @Override
    public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
        log.info("CusPagInterceptor---->beforeQuery");
        super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
    }

    @Override
    protected String autoCountSql(boolean optimizeCountSql, String sql) {
        log.info("CusPagInterceptor---->autoCountSql");
        return super.autoCountSql(optimizeCountSql, sql);
    }

    @Override
    protected boolean continuePage(IPage<?> page) {
        log.info("CusPagInterceptor---->continuePage");
        return super.continuePage(page);
    }

    @Override
    protected void handlerLimit(IPage<?> page) {
        log.info("CusPagInterceptor---->handlerLimit,current:{},size:{}",page.getCurrent(),page.getSize());
        super.handlerLimit(page);
    }
}
